<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Deque {
            constructor() {
                this.item = [];
            }

            //前端插入
            addFront(element) {
                this.item.unshift(element);
            }

            //后端插入
            addBack(element) {
                this.item.push(element);
            }

            //前端删除
            removeFront() {
                return this.item.shift();
            }

            //后端删除
            removeBack() {
                return this.item.pop();
            }

            peekFront() {
                if (this.isEmpty()) {
                    return undefined;
                } else {
                    return this.item[0];
                }
            }

            peekBack() {
                if (this.item.length === 0) {
                    return undefined;
                } else {
                    return this.item[this.item.length - 1];
                }
            }

            //toString()
            toString() {
                return this.item.toString();
            }
            //是否为空
            isEmpty() {
                return this.size() === 0;
            }

            //size
            size() {
                return this.item.length;
            }
        }


        function palidromeChecker(aSting) {
            //1.做预处理
            if (aSting === undefined || aSting === null || (aSting != null && aSting.length === 0)) {
                return false;
            }

            //2.对字符串做预处理
            const lowerString = aSting.toLowerCase().split(" ").join("");

            // return lowerString;

            const deque = new Deque();
            //3.字符串放到双端队列里
            for (let i = 0; i < lowerString.length; i++) {
                deque.addBack(lowerString.charAt(i));
            }



            //判断是否为回文
            let isEqual = true;
            let firstCase, lastCase;
            while (deque.size() > 1 && isEqual) {
                firstCase = deque.removeFront();
                lastCase = deque.removeBack();
                if (firstCase !== lastCase) {
                    isEqual = false;
                }

                // return deque;
            }
            //判断是否为回文

            return isEqual;

        }



        // let string = 'A bcdZXR';
        let string = 'A bcdcba';
        // console.log("deque", palidromeChecker(string));
        console.log(string);
        console.log("回文判断", palidromeChecker(string));
    </script>
</body>

</html>